/******************************************************************************
 * Name         : use.h
 * Title        : Pixel Shader Compiler
 * Author       : John Russell
 * Created      : Jan 2002
 *
 * Copyright    : 2002-2007 by Imagination Technologies Limited.
 *              : All rights reserved. No part of this software, either
 *              : material or conceptual may be copied or distributed,
 *              : transmitted, transcribed, stored in a retrieval system or
 *              : translated into any human or computer language in any form
 *              : by any means,electronic, mechanical, manual or otherwise,
 *              : or disclosed to third parties without the express written
 *              : permission of Imagination Technologies Limited,
 *              : Home Park Estate, Kings Langley, Hertfordshire,
 *              : WD4 8LZ, U.K.
 *
 * Modifications:-
 * $Log: use.h $
 *****************************************************************************/

#ifndef __USEASM_USE_H
#define __USEASM_USE_H

#include "pvr_debug.h"
#include "img_defs.h"
#include "img_types.h"

#include "sgxdefs.h"

typedef enum UseasmOpcodeTAG
{
	USEASM_OP_FMAD,
	USEASM_OP_FADM,
	USEASM_OP_FMSA,
	USEASM_OP_FFRC,
	USEASM_OP_FRCP,
	USEASM_OP_FRSQ,
	USEASM_OP_FLOG,
	USEASM_OP_FEXP,
	USEASM_OP_FSQRT,
	USEASM_OP_FSIN,
	USEASM_OP_FCOS,
	USEASM_OP_FDP,
	USEASM_OP_FMIN,
	USEASM_OP_FMAX,
	USEASM_OP_FDSX,
	USEASM_OP_FDSY,
	USEASM_OP_FMAD16,
	USEASM_OP_FMINMAX,
	USEASM_OP_FMAXMIN,
	USEASM_OP_EFO,
	USEASM_OP_PCKF16F32,
	USEASM_OP_PCKF16F16,
	USEASM_OP_PCKF16U16,
	USEASM_OP_PCKF16S16,
	USEASM_OP_PCKU16F32,
	USEASM_OP_PCKU16F16,
	USEASM_OP_PCKU16U16,
	USEASM_OP_PCKU16S16,
	USEASM_OP_PCKS16F32,
	USEASM_OP_PCKS16F16,
	USEASM_OP_PCKS16U16,
	USEASM_OP_PCKS16S16,
	USEASM_OP_PCKU8F32,
	USEASM_OP_PCKU8F16,
	USEASM_OP_PCKU8U16,
	USEASM_OP_PCKU8S16,
	USEASM_OP_PCKS8F32,
	USEASM_OP_PCKS8F16,
	USEASM_OP_PCKS8U16,
	USEASM_OP_PCKS8S16,
	USEASM_OP_PCKO8F32,
	USEASM_OP_PCKO8F16,
	USEASM_OP_PCKO8U16,
	USEASM_OP_PCKO8S16,
	USEASM_OP_PCKC10F32,
	USEASM_OP_PCKC10F16,
	USEASM_OP_PCKC10U16,
	USEASM_OP_PCKC10S16,
	USEASM_OP_UNPCKF32F32,
	USEASM_OP_UNPCKF32F16,
	USEASM_OP_UNPCKF32U16,
	USEASM_OP_UNPCKF32S16,
	USEASM_OP_UNPCKF32U8,
	USEASM_OP_UNPCKF32S8,
	USEASM_OP_UNPCKF32O8,
	USEASM_OP_UNPCKF32C10,
	USEASM_OP_UNPCKF16F16,
	USEASM_OP_UNPCKF16U16,
	USEASM_OP_UNPCKF16S16,
	USEASM_OP_UNPCKF16U8,
	USEASM_OP_UNPCKF16S8,
	USEASM_OP_UNPCKF16O8,
	USEASM_OP_UNPCKF16C10,
	USEASM_OP_UNPCKU16F16,
	USEASM_OP_UNPCKU16U16,
	USEASM_OP_UNPCKU16S16,
	USEASM_OP_UNPCKU16U8,
	USEASM_OP_UNPCKU16S8,
	USEASM_OP_UNPCKU16O8,
	USEASM_OP_UNPCKU16C10,
	USEASM_OP_UNPCKS16F16,
	USEASM_OP_UNPCKS16U16,
	USEASM_OP_UNPCKS16S16,
	USEASM_OP_UNPCKS16U8,
	USEASM_OP_UNPCKS16S8,
	USEASM_OP_UNPCKS16O8,
	USEASM_OP_UNPCKS16C10,
	USEASM_OP_UNPCKU8U8,
	USEASM_OP_UNPCKC10C10,
	USEASM_OP_AND,
	USEASM_OP_OR,
	USEASM_OP_XOR,
	USEASM_OP_SHL,
	USEASM_OP_SHR,
	USEASM_OP_ASR,
	USEASM_OP_ROL,
	USEASM_OP_RLP,
	USEASM_OP_SOP2,
	USEASM_OP_SOP2WM,
	USEASM_OP_SOP3,
	USEASM_OP_U8DOT3,
	USEASM_OP_U8DOT4,
	USEASM_OP_U16DOT3,
	USEASM_OP_U16DOT4,
	USEASM_OP_U8DOT3OFF,
	USEASM_OP_U8DOT4OFF,
	USEASM_OP_U16DOT3OFF,
	USEASM_OP_U16DOT4OFF,
	USEASM_OP_IMA8,
	USEASM_OP_IMA16,
	USEASM_OP_IMAE,
	USEASM_OP_IMA32,
	USEASM_OP_IDIV,
	USEASM_OP_ADIF,
	USEASM_OP_ADIFSUM,
	USEASM_OP_FIRV,
	USEASM_OP_FIRVH,
	USEASM_OP_BILIN,
	USEASM_OP_FIRH,
	USEASM_OP_FIRHH,
	USEASM_OP_SSUM16,
	USEASM_OP_SMP1D,
	USEASM_OP_SMP2D,
	USEASM_OP_SMP3D,
	USEASM_OP_SMP1DBIAS,
	USEASM_OP_SMP2DBIAS,
	USEASM_OP_SMP3DBIAS,
	USEASM_OP_SMP1DREPLACE,
	USEASM_OP_SMP2DREPLACE,
	USEASM_OP_SMP3DREPLACE,
	USEASM_OP_SMP1DGRAD,
	USEASM_OP_SMP2DGRAD,
	USEASM_OP_SMP3DGRAD,
	USEASM_OP_LDAB,
	USEASM_OP_LDAW,
	USEASM_OP_LDAD,
	USEASM_OP_LDAQ,
	USEASM_OP_STAB,
	USEASM_OP_STAW,
	USEASM_OP_STAD,
	USEASM_OP_STAQ,
	USEASM_OP_LDLB,
	USEASM_OP_LDLW,
	USEASM_OP_LDLD,
	USEASM_OP_LDLQ,
	USEASM_OP_STLB,
	USEASM_OP_STLW,
	USEASM_OP_STLD,
	USEASM_OP_STLQ,
	USEASM_OP_LDTB,
	USEASM_OP_LDTW,
	USEASM_OP_LDTD,
	USEASM_OP_LDTQ,
	USEASM_OP_STTB,
	USEASM_OP_STTW,
	USEASM_OP_STTD,
	USEASM_OP_STTQ,
	USEASM_OP_ELDD,
	USEASM_OP_ELDQ,
	USEASM_OP_BA,
	USEASM_OP_BR,
	USEASM_OP_LAPC,
	USEASM_OP_BEXCEPTION,
	USEASM_OP_IDF,
	USEASM_OP_WDF,
	USEASM_OP_LIMM,
	USEASM_OP_EMITPIXEL1,
	USEASM_OP_EMITPIXEL2,
	USEASM_OP_EMITPIXEL,
	USEASM_OP_EMITSTATE,
	USEASM_OP_EMITVERTEX,
	USEASM_OP_EMITPRIMITIVE,
	USEASM_OP_EMITPDS,
	USEASM_OP_MOV,
	USEASM_OP_FMOV,
	USEASM_OP_FMUL,
	USEASM_OP_FADD,
	USEASM_OP_FSSQ,
	USEASM_OP_LABEL,
	USEASM_OP_FSUB,
	USEASM_OP_SETPGT,
	USEASM_OP_SETPGTE,
	USEASM_OP_SETPEQ,
	USEASM_OP_SETPLT,
	USEASM_OP_SETPLTE,
	USEASM_OP_SETPNEQ,
	USEASM_OP_SDM,
	USEASM_OP_SDA,
	USEASM_OP_AMM,
	USEASM_OP_SMM,
	USEASM_OP_AMS,
	USEASM_OP_SMS,
	USEASM_OP_DMA,
	USEASM_OP_NOP,
	USEASM_OP_FTZ,
	USEASM_OP_FTNZ,
	USEASM_OP_U16TZ,
	USEASM_OP_U16TNZ,
	USEASM_OP_SMOA,
	USEASM_OP_SMR,
	USEASM_OP_SMLSI,
	USEASM_OP_SMBO,
	USEASM_OP_IMO,
	USEASM_OP_SETFC,
	USEASM_OP_FDP3,
	USEASM_OP_FDP4,
	USEASM_OP_FDPC,
	USEASM_OP_FDPC3,
	USEASM_OP_FDPC4,
	USEASM_OP_FDDP,
	USEASM_OP_FDDP3,
	USEASM_OP_FDDP4,
	USEASM_OP_FDDPC,
	USEASM_OP_FDDPC3,
	USEASM_OP_FDDPC4,
	USEASM_OP_LOCK,
	USEASM_OP_RELEASE,
	USEASM_OP_FSUBFLR,
	USEASM_OP_LDR,
	USEASM_OP_STR,
	USEASM_OP_PCOEFF,
	USEASM_OP_PTOFF,
	USEASM_OP_ATST8,
	USEASM_OP_DEPTHF,
	USEASM_OP_WOP,
	USEASM_OP_SETM,
	USEASM_OP_PHAS,
	USEASM_OP_PHASIMM,
	USEASM_OP_AINTRP1,
	USEASM_OP_AINTRP2,
	USEASM_OP_AADD,
	USEASM_OP_ASUB,
	USEASM_OP_ASOP,
	USEASM_OP_ARSOP,
	USEASM_OP_ALRP,
	USEASM_OP_LRP1,
	USEASM_OP_LRP2,
	USEASM_OP_ASOP2,
	USEASM_OP_IADD16,
	USEASM_OP_ISUB16,
	USEASM_OP_IMUL16,
	USEASM_OP_IADDU16,
	USEASM_OP_ISUBU16,
	USEASM_OP_IMULU16,
	USEASM_OP_IADD32,
	USEASM_OP_IADD8,
	USEASM_OP_ISUB8,
	USEASM_OP_IMUL8,
	USEASM_OP_IMULU8,
	USEASM_OP_IMOV16,
	USEASM_OP_IADDU32,
	USEASM_OP_PADDING,
	USEASM_OP_MOVC,
	USEASM_OP_MOVMSK,
	USEASM_OP_FPMA,
	USEASM_OP_IADDU8,
	USEASM_OP_ISUBU8,
	USEASM_OP_FPMUL8,
	USEASM_OP_FPADD8,
	USEASM_OP_FPSUB8,
	USEASM_OP_SABLND,
	USEASM_OP_FNRM32,
	USEASM_OP_FNRM16,
	USEASM_OP_MOEST,
	USEASM_OP_CF,
	USEASM_OP_CI,
	USEASM_OP_CFI,
	USEASM_OP_EMITMTEVERTEX,
	USEASM_OP_EMITMTESTATE,
	USEASM_OP_EMITVCBVERTEX,
	USEASM_OP_EMITVCBSTATE,
	USEASM_OP_VDP3,
	USEASM_OP_VDP4,
	USEASM_OP_VMAD3,
	USEASM_OP_VMAD4,
	USEASM_OP_VMUL3,
	USEASM_OP_VMUL4,
	USEASM_OP_VADD3,
	USEASM_OP_VADD4,
	USEASM_OP_VSUB3,
	USEASM_OP_VSUB4,
	USEASM_OP_VSSQ3,
	USEASM_OP_VSSQ4,
	USEASM_OP_VMOV3,
	USEASM_OP_VMOV4,
	USEASM_OP_VMOV,
	USEASM_OP_VMOVC,
	USEASM_OP_VMOVCU8,
	USEASM_OP_VMAD,
	USEASM_OP_VMUL,
	USEASM_OP_VADD,
	USEASM_OP_VFRC,
	USEASM_OP_VMIN,
	USEASM_OP_VMAX,
	USEASM_OP_VDSX,
	USEASM_OP_VDSY,
	USEASM_OP_VDP,
	USEASM_OP_VSUB,
	USEASM_OP_VF16MAD,
	USEASM_OP_VF16MUL,
	USEASM_OP_VF16ADD,
	USEASM_OP_VF16FRC,
	USEASM_OP_VF16DSX,
	USEASM_OP_VF16DSY,
	USEASM_OP_VF16MIN,
	USEASM_OP_VF16MAX,
	USEASM_OP_VF16DP,
	USEASM_OP_VF16SUB,
	USEASM_OP_VRCP,
	USEASM_OP_VRSQ,
	USEASM_OP_VLOG,
	USEASM_OP_VEXP,
	USEASM_OP_VPCKU8U8,
	USEASM_OP_VPCKU8S8,
	USEASM_OP_VPCKU8O8,
	USEASM_OP_VPCKU8U16,
	USEASM_OP_VPCKU8S16,
	USEASM_OP_VPCKU8F16,
	USEASM_OP_VPCKU8F32,
	USEASM_OP_VPCKS8U8,
	USEASM_OP_VPCKS8S8,
	USEASM_OP_VPCKS8O8,
	USEASM_OP_VPCKS8U16,
	USEASM_OP_VPCKS8S16,
	USEASM_OP_VPCKS8F16,
	USEASM_OP_VPCKS8F32,
	USEASM_OP_VPCKO8U8,
	USEASM_OP_VPCKO8S8,
	USEASM_OP_VPCKO8O8,
	USEASM_OP_VPCKO8U16,
	USEASM_OP_VPCKO8S16,
	USEASM_OP_VPCKO8F16,
	USEASM_OP_VPCKO8F32,
	USEASM_OP_VPCKU16U8,
	USEASM_OP_VPCKU16S8,
	USEASM_OP_VPCKU16O8,
	USEASM_OP_VPCKU16U16,
	USEASM_OP_VPCKU16S16,
	USEASM_OP_VPCKU16F16,
	USEASM_OP_VPCKU16F32,
	USEASM_OP_VPCKS16U8,
	USEASM_OP_VPCKS16S8,
	USEASM_OP_VPCKS16O8,
	USEASM_OP_VPCKS16U16,
	USEASM_OP_VPCKS16S16,
	USEASM_OP_VPCKS16F16,
	USEASM_OP_VPCKS16F32,
	USEASM_OP_VPCKF16U8,
	USEASM_OP_VPCKF16S8,
	USEASM_OP_VPCKF16O8,
	USEASM_OP_VPCKF16U16,
	USEASM_OP_VPCKF16S16,
	USEASM_OP_VPCKF16F16,
	USEASM_OP_VPCKF16F32,
	USEASM_OP_VPCKF16C10,
	USEASM_OP_VPCKF32U8,
	USEASM_OP_VPCKF32S8,
	USEASM_OP_VPCKF32O8,
	USEASM_OP_VPCKF32U16,
	USEASM_OP_VPCKF32S16,
	USEASM_OP_VPCKF32F16,
	USEASM_OP_VPCKF32F32,
	USEASM_OP_VPCKF32C10,
	USEASM_OP_VPCKC10F16,
	USEASM_OP_VPCKC10F32,
	USEASM_OP_VPCKC10C10,
	USEASM_OP_IDXSCR,
	USEASM_OP_IDXSCW,
	USEASM_OP_SPRVV,
	USEASM_OP_ISUB32,
	USEASM_OP_ISUBU32,
	USEASM_OP_CNDST,
	USEASM_OP_CNDEF,
	USEASM_OP_CNDSM,
	USEASM_OP_CNDLT,
	USEASM_OP_CNDEND,
	USEASM_OP_LDATOMIC,
	USEASM_OP_UNPCKU8S8,
	USEASM_OP_UNPCKS8U8,
	USEASM_OP_MAXIMUM,
	USEASM_OP_UNDEF
}UseasmOpcode;
typedef UseasmOpcode USEASM_OPCODE;

typedef enum UseasmRegTypeTAG
{
	USEASM_REGTYPE_TEMP				  = 0,
	USEASM_REGTYPE_OUTPUT			  = 1,
	USEASM_REGTYPE_PRIMATTR			  = 2,
	USEASM_REGTYPE_SECATTR			  = 3,
	USEASM_REGTYPE_INDEX			  = 4,
	USEASM_REGTYPE_GLOBAL			  = 5,
	USEASM_REGTYPE_FPCONSTANT		  = 6,
	USEASM_REGTYPE_FPINTERNAL		  = 7,
	USEASM_REGTYPE_IMMEDIATE		  = 8,
	USEASM_REGTYPE_LINK				  = 9,
	USEASM_REGTYPE_DRC				  = 10,
	USEASM_REGTYPE_LABEL			  = 11,
	USEASM_REGTYPE_PREDICATE		  = 12,
	USEASM_REGTYPE_CLIPPLANE		  = 13,
	USEASM_REGTYPE_ADDRESSMODE		  = 14,
	USEASM_REGTYPE_SWIZZLE			  = 15,
	USEASM_REGTYPE_INTSRCSEL		  = 16,
	USEASM_REGTYPE_FILTERCOEFF		  = 17,
	USEASM_REGTYPE_LABEL_WITH_OFFSET  = 18,
	USEASM_REGTYPE_TEMP_NAMED		  = 19,
	USEASM_REGTYPE_FLOATIMMEDIATE	  = 20,
    /* ref(i): Unresolved reference to an object identified by IMG_UINT32 i */
	USEASM_REGTYPE_REF                = 21, 
	USEASM_REGTYPE_MAXIMUM			  = 22,
	USEASM_REGTYPE_UNDEF              = 0x7fff
} UseasmRegType;
typedef UseasmRegType USEASM_REGTYPE;

typedef IMG_UINT32 USEASM_OPFLAGS1;
#define USEASM_OPFLAGS1_SKIPINVALID     0x00000001U
#define USEASM_OPFLAGS1_MOVC_FMTI8      0x00000002U
#define USEASM_OPFLAGS1_SYNCSTART       0x00000004U
#define USEASM_OPFLAGS1_NOSCHED         0x00000008U
#define USEASM_OPFLAGS1_END             0x00020000U
#define USEASM_OPFLAGS1_SYNCEND         0x00040000U
#define USEASM_OPFLAGS1_SAVELINK        0x00080000U
#define USEASM_OPFLAGS1_PARTIAL         0x00100000U
#define USEASM_OPFLAGS1_MOVC_FMTMASK    0x00200000U
#define USEASM_OPFLAGS1_MONITOR         0x00400000U
#define USEASM_OPFLAGS1_ABS             0x00800000U
#define USEASM_OPFLAGS1_ROUNDENABLE     0x01000000U
#define USEASM_OPFLAGS1_MAINISSUE       0x02000000U
#define USEASM_OPFLAGS1_MOVC_FMTF16	    0x04000000U
#define USEASM_OPFLAGS1_PREINCREMENT    0x08000000U
#define USEASM_OPFLAGS1_POSTINCREMENT   0x10000000U
#define USEASM_OPFLAGS1_RANGEENABLE     0x20000000U
#define USEASM_OPFLAGS1_TESTENABLE      0x40000000U
#define USEASM_OPFLAGS1_FETCHENABLE     0x80000000U

#define USEASM_OPFLAGS1_REPEAT_SHIFT  (4)
#define USEASM_OPFLAGS1_REPEAT_CLRMSK (0xFFFFFE0FU)
#define USEASM_OPFLAGS1_MASK_SHIFT    (9)
#define USEASM_OPFLAGS1_MASK_CLRMSK   (0xFFFFE1FFU)
#define	USEASM_OPFLAGS1_PRED_SHIFT    (13)
#define USEASM_OPFLAGS1_PRED_CLRMSK   (0xFFFE1FFFU)

typedef IMG_UINT32 USEASM_OPFLAGS2;
#define USEASM_OPFLAGS2_ONCEONLY           0x00000001U
#define USEASM_OPFLAGS2_COISSUE            0x00000002U
#define USEASM_OPFLAGS2_BYPASSCACHE        0x00000004U
#define USEASM_OPFLAGS2_FORCELINEFILL      0x00000008U
#define USEASM_OPFLAGS2_TASKSTART          0x00000010U
#define USEASM_OPFLAGS2_TASKEND            0x00000020U
#define USEASM_OPFLAGS2_SCALE              0x00000100U
#define USEASM_OPFLAGS2_INCSGN             0x00000200U
#define USEASM_OPFLAGS2_SAT                0x00000400U
#define USEASM_OPFLAGS2_UNSIGNED           0x00000800U
#define USEASM_OPFLAGS2_SIGNED             0x00001000U
#define USEASM_OPFLAGS2_MOVC_FMTI16        0x00080000U
#define USEASM_OPFLAGS2_MOVC_FMTI32        0x00100000U
#define USEASM_OPFLAGS2_MOVC_FMTF32        0x00200000U
#define USEASM_OPFLAGS2_TYPEPRESERVE       0x00400000U
#define USEASM_OPFLAGS2_MOVC_FMTI10        0x00800000U
#define USEASM_OPFLAGS2_FORMATSELECT       0x01000000U
#define USEASM_OPFLAGS2_C10                0x02000000U
#define USEASM_OPFLAGS2_TOGGLEOUTFILES     0x04000000U
#define USEASM_OPFLAGS2_MOEPOFF            0x08000000U

#define USEASM_OPFLAGS2_PERINSTMOE (0x10000000U)
#define USEASM_OPFLAGS2_PERINSTMOE_INCS0 (0x20000000U)
#define USEASM_OPFLAGS2_PERINSTMOE_INCS1 (0x40000000U)
#define USEASM_OPFLAGS2_PERINSTMOE_INCS2 (0x80000000U)

#define USEASM_OPFLAGS2_RSHIFT_SHIFT  (15)
#define USEASM_OPFLAGS2_RSHIFT_CLRMSK (0xFFF87FFFU)

typedef enum _USEASM_OPFLAGS3_
{
	USEASM_OPFLAGS3_PCFF32			= 0x00000001,
	USEASM_OPFLAGS3_PCFF16			= 0x00000002,
	USEASM_OPFLAGS3_SAMPLEDATA		= 0x00000004,
	USEASM_OPFLAGS3_SAMPLEINFO		= 0x00000008,
	USEASM_OPFLAGS3_SYNCENDNOTTAKEN	= 0x00000010,
	USEASM_OPFLAGS3_TRIGGER			= 0x00000020,
	USEASM_OPFLAGS3_TWOPART			= 0x00000040,
	USEASM_OPFLAGS3_THREEPART		= 0x00000080,
	USEASM_OPFLAGS3_CUT				= 0x00000100,
	USEASM_OPFLAGS3_BYPASSL1		= 0x00000200,
	USEASM_OPFLAGS3_GPIEXT			= 0x00000400,
	USEASM_OPFLAGS3_GLOBAL			= 0x00000800,
	USEASM_OPFLAGS3_DM_NOMATCH		= 0x00001000,
	USEASM_OPFLAGS3_NOREAD			= 0x00002000,
	USEASM_OPFLAGS3_PWAIT			= 0x00004000,
	USEASM_OPFLAGS3_SAMPLEDATAANDINFO
									= 0x00008000,
	USEASM_OPFLAGS3_MINPACK			= 0x00010000,
	USEASM_OPFLAGS3_STEP1			= 0x00020000,
	USEASM_OPFLAGS3_STEP2			= 0x00040000,
	USEASM_OPFLAGS3_SAMPLEMASK		= 0x00080000,
	USEASM_OPFLAGS3_FREEP			= 0x00100000,
	USEASM_OPFLAGS3_SKIPINVALIDON	= 0x00200000,
	USEASM_OPFLAGS3_ALLINSTANCES	= 0x00400000,
	USEASM_OPFLAGS3_ANYINSTANCES	= 0x00800000
} USEASM_OPFLAGS3;

typedef enum _USEASM_PRED_
{
	USEASM_PRED_NONE = 0,
	USEASM_PRED_P0 = 1,
    USEASM_PRED_P1 = 2,
	USEASM_PRED_NEGP0 = 3,
	USEASM_PRED_NEGP1 = 4,
    USEASM_PRED_P2 = 5,
	USEASM_PRED_P3 = 6,
    USEASM_PRED_PN = 7,
	USEASM_PRED_NEGP2 = 8
} USEASM_PRED;

typedef IMG_UINT32 USEASM_ARGFLAGS;
#define	USEASM_ARGFLAGS_NEGATE            0x00000001U
#define	USEASM_ARGFLAGS_ABSOLUTE          0x00000002U
#define	USEASM_ARGFLAGS_REQUIRESGPI2	  0x00000004U
#define	USEASM_ARGFLAGS_INVERT            0x00000800U
#define	USEASM_ARGFLAGS_LOW               0x00001000U
#define	USEASM_ARGFLAGS_HIGH              0x00002000U
#define	USEASM_ARGFLAGS_ALPHA             0x00004000U
#define	USEASM_ARGFLAGS_COMPLEMENT        0x00008000U
#define	USEASM_ARGFLAGS_DISABLEWB         0x00010000U
#define	USEASM_ARGFLAGS_BYTEMSK_PRESENT   0x00100000U
#define	USEASM_ARGFLAGS_FMTF32            0x00200000U
#define	USEASM_ARGFLAGS_FMTF16            0x00400000U
#define	USEASM_ARGFLAGS_FMTU8             0x00800000U
#define	USEASM_ARGFLAGS_FMTC10            0x01000000U
#define USEASM_ARGFLAGS_REQUIREMOE		  0x08000000U
#define USEASM_ARGFLAGS_NOT				  0x10000000U

#define USEASM_ARGFLAGS_COMP_SHIFT       (5)
#define USEASM_ARGFLAGS_COMP_CLRMSK      (0xFFFFFF9FU)
#define USEASM_ARGFLAGS_BYTEMSK_SHIFT    (7)
#define USEASM_ARGFLAGS_BYTEMSK_CLRMSK   (0xFFFFF87FU)


typedef enum _USEASM_MAD16SWZ_
{
	USEASM_MAD16SWZ_LOWHIGH			= (0),
	USEASM_MAD16SWZ_LOWLOW			= (1),
	USEASM_MAD16SWZ_HIGHHIGH		= (2),
	USEASM_MAD16SWZ_CVTFROMF32		= (3)
} USEASM_MAD16SWZ;
#define USEASM_ARGFLAGS_MAD16SWZ_SHIFT  (25)
#define USEASM_ARGFLAGS_MAD16SWZ_CLRMSK (0xF9FFFFFFU)


typedef enum _USEREG_MASK_
{
	USEREG_MASK_X    = (1U << 0),
	USEREG_MASK_Y	 = (1U << 1),
	USEREG_MASK_Z    = (1U << 2),
	USEREG_MASK_W	 = (1U << 3)
} USEREG_MASK;
#define USEREG_MASK_FULL (USEREG_MASK_X | USEREG_MASK_Y | USEREG_MASK_Z | USEREG_MASK_W)
#define USEREG_MASK_XY	 (USEREG_MASK_X | USEREG_MASK_Y)
#define USEREG_MASK_XYZ	 (USEREG_MASK_X | USEREG_MASK_Y | USEREG_MASK_Z)
#define USEREG_MASK_XYZW USEREG_MASK_FULL

typedef enum _USEREG_INDEX_
{
	USEREG_INDEX_NONE     = 0,
	USEREG_INDEX_L		  = 1,
	USEREG_INDEX_H		  = 2
} USEREG_INDEX;

typedef enum _USEASM_TEST_SIGN_
{
	USEASM_TEST_SIGN_TRUE			= 0,
	USEASM_TEST_SIGN_NEGATIVE		= 1,
	USEASM_TEST_SIGN_POSITIVE		= 2,
	USEASM_TEST_SIGN_UNDEF			= 0x7FFF
} USEASM_TEST_SIGN;
#define USEASM_TEST_SIGN_SHIFT  (0)
#define USEASM_TEST_SIGN_CLRMSK (0xFFFFFFFCU)

typedef enum _USEASM_TEST_ZERO_
{
	USEASM_TEST_ZERO_TRUE			= 0,
	USEASM_TEST_ZERO_ZERO			= 1,
	USEASM_TEST_ZERO_NONZERO		= 2,
	USEASM_TEST_ZERO_UNDEF			= 0x7FFF
} USEASM_TEST_ZERO;
#define USEASM_TEST_ZERO_SHIFT (2)
#define USEASM_TEST_ZERO_CLRMSK (0xFFFFFFF3U)


typedef enum _USEASM_TEST_CRCOMB_
{
	USEASM_TEST_CRCOMB_OR			= 0x00000000U,
	USEASM_TEST_CRCOMB_AND			= 0x00000010U
} USEASM_TEST_CRCOMB;

#define USEASM_TEST_TESTTYPE_MASK	((~USEASM_TEST_SIGN_CLRMSK) | (~USEASM_TEST_ZERO_CLRMSK) | USEASM_TEST_CRCOMB_AND)

typedef enum _USEASM_TEST_CHANSEL_
{
	USEASM_TEST_CHANSEL_C0			= 0,
	USEASM_TEST_CHANSEL_C1			= 1,
	USEASM_TEST_CHANSEL_C2			= 2,
	USEASM_TEST_CHANSEL_C3			= 3,
	USEASM_TEST_CHANSEL_ANDALL		= 4,
	USEASM_TEST_CHANSEL_ORALL		= 5,
	USEASM_TEST_CHANSEL_AND02		= 6,
	USEASM_TEST_CHANSEL_OR02		= 7,
	USEASM_TEST_CHANSEL_PERCHAN		= 8
} USEASM_TEST_CHANSEL;
#define USEASM_TEST_CHANSEL_SHIFT  (5)
#define USEASM_TEST_CHANSEL_CLRMSK (0xFFFFFE1FU)

typedef enum _USEASM_TEST_MASK_
{
	USEASM_TEST_MASK_NONE			= 0,
	USEASM_TEST_MASK_BYTE			= 1,
	USEASM_TEST_MASK_WORD			= 2,
	USEASM_TEST_MASK_DWORD			= 3,
	USEASM_TEST_MASK_PREC			= 4,
	USEASM_TEST_MASK_NUM			= 5,
	USEASM_TEST_MASK_UNDEF			= 0x7FFF
} USEASM_TEST_MASK;
#define USEASM_TEST_MASK_SHIFT	 (9)
#define USEASM_TEST_MASK_CLRMSK	 (0xFFFFF0FFU)

#define USEASM_TEST_COND_CLRMSK			0xFFFFFFE0U

typedef enum _USEASM_INTSRCSEL_
{
	USEASM_INTSRCSEL_ZERO			= (0),
	USEASM_INTSRCSEL_ONE			= (1),
	USEASM_INTSRCSEL_SRCALPHASAT	= (2),
	USEASM_INTSRCSEL_RSRCALPHASAT	= (3),
	USEASM_INTSRCSEL_SRC0			= (4),
	USEASM_INTSRCSEL_SRC1			= (5),
	USEASM_INTSRCSEL_SRC2			= (6),
	USEASM_INTSRCSEL_SRC0ALPHA		= (7),
	USEASM_INTSRCSEL_SRC1ALPHA		= (8),
	USEASM_INTSRCSEL_SRC2ALPHA		= (9),
	USEASM_INTSRCSEL_CX1			= (10),
	USEASM_INTSRCSEL_CX2			= (11),
	USEASM_INTSRCSEL_CX4			= (12),
	USEASM_INTSRCSEL_CX8			= (13),
	USEASM_INTSRCSEL_AX1			= (14),
	USEASM_INTSRCSEL_AX2			= (15),
	USEASM_INTSRCSEL_AX4			= (16),
	USEASM_INTSRCSEL_AX8			= (17),
	USEASM_INTSRCSEL_ADD			= (18),
	USEASM_INTSRCSEL_SUB			= (19),
	USEASM_INTSRCSEL_NEG			= (20),
	USEASM_INTSRCSEL_NONE			= (21),
	USEASM_INTSRCSEL_MIN			= (22),
	USEASM_INTSRCSEL_MAX			= (23),
	USEASM_INTSRCSEL_SRC2SCALE		= (24),
	USEASM_INTSRCSEL_ZEROS			= (25),
	USEASM_INTSRCSEL_COMP			= (26),
	USEASM_INTSRCSEL_PLUSSRC2DOT2	= (27),
	USEASM_INTSRCSEL_IADD			= (28),
	USEASM_INTSRCSEL_SCALE			= (29),
	USEASM_INTSRCSEL_U8				= (30),
	USEASM_INTSRCSEL_S8				= (31),
	USEASM_INTSRCSEL_O8				= (32),
	USEASM_INTSRCSEL_Z16			= (39),
	USEASM_INTSRCSEL_S16			= (40),
	USEASM_INTSRCSEL_U32			= (41),
	USEASM_INTSRCSEL_CINENABLE		= (42),
	USEASM_INTSRCSEL_COUTENABLE		= (43),
	USEASM_INTSRCSEL_U16			= (44),
	USEASM_INTSRCSEL_INTERLEAVED	= (45),
	USEASM_INTSRCSEL_PLANAR			= (46),
	USEASM_INTSRCSEL_SRC01			= (47),
	USEASM_INTSRCSEL_SRC23			= (48),
	USEASM_INTSRCSEL_DST01			= (49),
	USEASM_INTSRCSEL_DST23			= (50),
	USEASM_INTSRCSEL_RND			= (51),
	USEASM_INTSRCSEL_TWOSIDED		= (52),
	USEASM_INTSRCSEL_FEEDBACK		= (53),
	USEASM_INTSRCSEL_NOFEEDBACK		= (54),
	USEASM_INTSRCSEL_OPTDWD			= (55),
	USEASM_INTSRCSEL_IDST			= (56),
	USEASM_INTSRCSEL_ROUNDDOWN		= (57),
	USEASM_INTSRCSEL_ROUNDNEAREST	= (58),
	USEASM_INTSRCSEL_ROUNDUP		= (59),
	USEASM_INTSRCSEL_PIXEL			= (60),
	USEASM_INTSRCSEL_SAMPLE			= (61),
	USEASM_INTSRCSEL_SELECTIVE		= (62),
	USEASM_INTSRCSEL_PT				= (63),
	USEASM_INTSRCSEL_VCULL			= (64),
	USEASM_INTSRCSEL_END			= (65),
	USEASM_INTSRCSEL_PARALLEL		= (66),
	USEASM_INTSRCSEL_PERINSTANCE	= (67),
	USEASM_INTSRCSEL_SRCNEG			= (68),
	USEASM_INTSRCSEL_SRCABS			= (69),
	USEASM_INTSRCSEL_INCREMENTUS	= (70),
	USEASM_INTSRCSEL_INCREMENTGPI	= (71),
	USEASM_INTSRCSEL_INCREMENTBOTH	= (72),
	USEASM_INTSRCSEL_INCREMENTMOE	= (73),
	USEASM_INTSRCSEL_INCREMENTALL	= (74),
	USEASM_INTSRCSEL_INCREMENTS1	= (75),
	USEASM_INTSRCSEL_INCREMENTS2	= (76),
	USEASM_INTSRCSEL_INCREMENTS1S2	= (77),
	USEASM_INTSRCSEL_F32			= (78),
	USEASM_INTSRCSEL_F16			= (79),
	USEASM_INTSRCSEL_OR				= (80),
	USEASM_INTSRCSEL_XOR			= (81),
	USEASM_INTSRCSEL_AND			= (82),
	USEASM_INTSRCSEL_REVSUB			= (83),
	USEASM_INTSRCSEL_XCHG			= (84),
	USEASM_INTSRCSEL_TRUE			= (85),
	USEASM_INTSRCSEL_FALSE			= (86),
	USEASM_INTSRCSEL_IMIN			= (87),
	USEASM_INTSRCSEL_IMAX			= (88),
	USEASM_INTSRCSEL_UMIN			= (89),
	USEASM_INTSRCSEL_UMAX			= (90),
	USEASM_INTSRCSEL_UNDEF          = 0x7fff
} USEASM_INTSRCSEL;
#define USEASM_INTSRCSEL_ROUNDZERO (USEASM_INTSRCSEL_ZERO)

/* USEASM_SWIZZLE_FIELD_SIZE: Number of bits in a swizzle field. */
#define USEASM_SWIZZLE_FIELD_SIZE		(3)

/* USEASM_SWIZZLE_VALUE_MASK: Mask to extract the first swizzle value (in position 0). */
#define USEASM_SWIZZLE_VALUE_MASK		(7U)

/* USEASM_SWIZZLE: Form a complete swizzle. */
#define USEASM_SWIZZLE(XSEL, YSEL, ZSEL, WSEL)		((USEASM_SWIZZLE_SEL_##XSEL << (USEASM_SWIZZLE_FIELD_SIZE * 0)) | \
													 (USEASM_SWIZZLE_SEL_##YSEL << (USEASM_SWIZZLE_FIELD_SIZE * 1)) | \
													 (USEASM_SWIZZLE_SEL_##ZSEL << (USEASM_SWIZZLE_FIELD_SIZE * 2)) | \
													 (USEASM_SWIZZLE_SEL_##WSEL << (USEASM_SWIZZLE_FIELD_SIZE * 3)))

/* Swizzle field values. */
typedef enum _USEASM_SWIZZLE_SEL_
{
	USEASM_SWIZZLE_SEL_X			= (0),
	USEASM_SWIZZLE_SEL_Y			= (1),
	USEASM_SWIZZLE_SEL_Z			= (2),
	USEASM_SWIZZLE_SEL_W			= (3),
	USEASM_SWIZZLE_SEL_0			= (4),
	USEASM_SWIZZLE_SEL_1			= (5),
	USEASM_SWIZZLE_SEL_2			= (6),
	USEASM_SWIZZLE_SEL_HALF			= (7),
	USEASM_SWIZZLE_SEL_UNDEF		= (8)
} USEASM_SWIZZLE_SEL;

typedef struct _USE_REGISTER
{
	IMG_UINT32		uNumber;
	USEASM_REGTYPE	uType;
	IMG_UINT32		uFlags;
	IMG_UINT32		uIndex;
	IMG_UINT32		uNamedRegLink;
} USE_REGISTER, *PUSE_REGISTER;

#define USE_MAX_ARGUMENTS			(11)

typedef struct _USE_INST
{
	USEASM_OPCODE		uOpcode;
	IMG_UINT32			uFlags1;
	IMG_UINT32			uFlags2;
	IMG_UINT32			uFlags3;
	IMG_UINT32			uTest;
	USE_REGISTER		asArg[USE_MAX_ARGUMENTS];
	struct _USE_INST*	psPrev;
	struct _USE_INST*	psNext;
	IMG_UINT32			uSourceLine;
	IMG_PCHAR			pszSourceFile;
} USE_INST, *PUSE_INST;

typedef IMG_PVOID (IMG_CALLCONV *USEASM_REALLOCFN)(IMG_PVOID pvContext, IMG_PVOID pvOldBuf, IMG_UINT32 uNewSize, IMG_UINT32 uOldSize);
typedef IMG_UINT32 (IMG_CALLCONV *USEASM_GETLABELADDRFN)(IMG_PVOID pvContext, IMG_UINT32 uLabel);
typedef IMG_VOID (IMG_CALLCONV *USEASM_SETLABELADDRFN)(IMG_PVOID pvContext, IMG_UINT32 uLabel, IMG_UINT32 uAddress);
typedef IMG_PCHAR (IMG_CALLCONV *USEASM_GETLABELNAMEFN)(IMG_PVOID pvContext, IMG_UINT32 uLabel);
typedef IMG_VOID (IMG_CALLCONV *USEASM_ASSEMBLERERRORFN)(IMG_PVOID pvContext, PUSE_INST psInst, IMG_CHAR *pszFmt, ...) IMG_FORMAT_PRINTF(3, 4);
typedef IMG_VOID (IMG_CALLCONV *USEASM_LADDRNOTIFY)(IMG_UINT32 uAddress);

typedef struct _USEASM_CONTEXT
{
	IMG_PVOID				pvContext;
	IMG_PVOID				pvLabelState;
	USEASM_REALLOCFN		pfnRealloc;
	USEASM_GETLABELADDRFN	pfnGetLabelAddress;
	USEASM_SETLABELADDRFN	pfnSetLabelAddress;
	USEASM_GETLABELNAMEFN	pfnGetLabelName;
	USEASM_ASSEMBLERERRORFN	pfnAssemblerError;
	USEASM_LADDRNOTIFY		pfnLADDRNotify;
} USEASM_CONTEXT, *PUSEASM_CONTEXT;

#include "usedisasm.h"

IMG_UINT32 IMG_CALLCONV UseAssembleInstruction(PCSGX_CORE_DESC psTarget,
											   PUSE_INST psInst,
											   IMG_PUINT32 puBaseInst,
											   IMG_PUINT32 puInst,
											   IMG_UINT32 dwCodeOffset,
											   PUSEASM_CONTEXT psContext);

IMG_UINT32 IMG_CALLCONV UseAssembler(PCSGX_CORE_DESC psTarget,
									 PUSE_INST psInst,
									 IMG_PUINT32 puInst,
									 IMG_UINT32 uCodeOffset,
									 PUSEASM_CONTEXT psContext);

IMG_UINT32 IMG_CALLCONV UseGetOpcodeArgumentCount(IMG_UINT32 uOpcode);

IMG_BOOL IMG_CALLCONV UseIsTextureSampleOpcode(IMG_UINT32 uOpcode);

IMG_BOOL IMG_CALLCONV UseAcceptsSkipinvOpcode(IMG_UINT32 uOpcode);

IMG_BOOL IMG_CALLCONV UseAcceptsNoSchedOpcode(IMG_UINT32 uOpcode);

IMG_BOOL IMG_CALLCONV UseAcceptsNoSchedEnhancedOpcode(IMG_UINT32 uOpcode);

IMG_CHAR const * IMG_CALLCONV UseGetNameOpcode(IMG_UINT32 uOpcode);

IMG_BOOL OpcodeAcceptsSkipInv(IMG_UINT32 uOpcode);
IMG_BOOL OpcodeAcceptsNoSched(IMG_UINT32 uOpcode);
IMG_BOOL OpcodeAcceptsNoSchedEnhanced(IMG_UINT32 uOpcode);

IMG_UINT32 FloatToCstIndex(IMG_FLOAT f);

PCSGX_CORE_DESC IMG_CALLCONV UseAsmGetCoreDesc(PSGX_CORE_INFO psTarget);

/* Initialisation functions */
IMG_VOID UseAsmInitInst(PUSE_INST psInst);
IMG_VOID UseAsmInitReg(PUSE_REGISTER psReg);


#endif /* __USEASM_USE_H */

/******************************************************************************
 End of file (use.h)
******************************************************************************/

